﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.Common;
using Newtonsoft.Json;
using System.Text;
using System.IO;
using Hangjing.Model;
using Hangjing.DBUtility;
using Hangjing.SQLServerDAL;
using System.Collections.Specialized;

using Hangjing.meituanapi;
using Hangjing.WebCommon;

/// <summary>
/// 订单取消，美团调用
/// </summary>
public partial class api_meituan_heartbeat_cancelorderr : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();

        Hangjing.AppLog.AppLog.Info("美团订单来了");

       

        string developerId = Request["developerId"];
        if (developerId != Constant.mt_developerId)
        {
            Response.Write("{\"data\":\"error\"}");
            Response.End();

            return;
        }

        string ePoiId = Request["ePoiId"];
        string orderCancel = Server.UrlDecode(Request["orderCancel"]);

        apiResultInfo rs = new apiResultInfo();
        System.IO.Stream stream = Request.InputStream;//这是你获得的流
        if (stream != null && stream.Length > 10)
        {

            Hangjing.AppLog.AppLog.Info("stream.Length ：" + stream.Length);
            string jsondata = "";
            using (StreamReader reader = new StreamReader(stream))
            {
                jsondata = reader.ReadToEnd(); ;
            }

            Hangjing.AppLog.AppLog.Info("美团取消夜间 信息：" + jsondata);

            mtcancelinfo cancelinfo = JsonConvert.DeserializeObject<mtcancelinfo>(orderCancel);

            string mt_orderid = "m" + cancelinfo.orderId;

            new Custorder().AddOrderRecord(mt_orderid, 5, "ele", "美团取消了订单");
            ////订单取消
            string sql = "update Custorder set OrderStatus=5, OrderAttach = OrderAttach + '[取消原因："+cancelinfo.reason+"]' where OrderID='" + mt_orderid + "';update shopeleCustorder set OrderStatus=5, OrderAttach = OrderAttach + '[取消原因：" + cancelinfo.reason + "]' where OrderID='" + mt_orderid + "'";
            WebUtility.excutesql(sql);



            Response.Write("{\"data\":\"OK\"}");
        }
        else
        {
            Response.Write("{\"data\":\"error\"}");
        }





        Response.End();

    }
}